﻿using System.Configuration;

namespace WatiNCF.MsTest.Runner
{
    public class AssemblyConfigSectionHandler : ConfigurationSection
    {
        public AssemblyConfigSectionHandler()
        {
            
        }

        [ConfigurationProperty("assemblies", IsDefaultCollection = false)]
        public AssemblyConfigElementCollection Assemblies
        {
            get { return this["assemblies"] as AssemblyConfigElementCollection; }
        }
    }

    public class AssemblyConfigElementCollection : ConfigurationElementCollection
    {
        public AssemblyConfigElementCollection()
        {

        }

        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            return new AssemblyConfigElement(elementName);
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new AssemblyConfigElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((AssemblyConfigElement)element).Name;
        }

        public AssemblyConfigElement this[int index]
        {
            get
            {
                return (AssemblyConfigElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);

                }
                BaseAdd(index, value);
            }
        }
            
        
        
        public AssemblyConfigElement this[string Name]
        {
            get
            {
                return (AssemblyConfigElement)BaseGet(Name);
            }
        }

    }

    public class AssemblyConfigElement : ConfigurationElement
    {
        public AssemblyConfigElement()
        {
        }

        public AssemblyConfigElement(string name)
        {
            Name = name;
        }

        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }
    }
}